﻿using Unity.Entities;
using Unity.Transforms;
using UnityEngine;


public partial class GameManager : MonoBehaviour
{
    public static GameManager instance;

    public void Awake()
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        //Entity entity = entityManager.CreateEntity();
        //entityManager.AddComponentData(entity, new QuadTreeRootComp()
        //{
        //    treeRoot = new QuadTree().Setting(true, 5, 6).InitRect(0, 0, 100, 100).Init()
        //});
        if (instance != null)
        {
            Destroy(gameObject);
            return;
        }
        instance = this;
        World.DefaultGameObjectInjectionWorld.GetExistingSystem(typeof(GameSystemGroup));
    }
}

[UpdateInGroup(typeof(SimulationSystemGroup))]
[UpdateBefore(typeof(TransformSystemGroup))]
public partial class GameSystemGroup : ComponentSystemGroup
{
    protected override void OnCreate()
    {
        EnableSystemSorting = false;
        base.OnCreate();
        //初始化系统
        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(EnemySpawnerSystem))); //生成敌人
        //玩家输入
        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(InputSystem))); //输入处理
        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(PlayerInputHendleSystem))); //根据输入的值处理

        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(FireSystem)));
        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(ArrowSystem)));
        //Quad Tree
        //AddSystemToUpdateList(World.GetOrCreateSystem(typeof(QuadTreeSystem)));

        // 目标移动
        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(FollowTargetSystem)));

        //移动同步系统
        //AddSystemToUpdateList(World.GetOrCreateSystem(typeof(MoveSyncSystem)));

        // 转向系统
        //AddSystemToUpdateList(World.GetOrCreateSystem(typeof(SteeringSystem)));

        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(MovementSystem)));

        AddSystemToUpdateList(World.GetOrCreateSystem(typeof(DestroySystem)));
    }
}
